package org.fsconnector.cci;

import javax.naming.NamingException;
import javax.naming.Reference;
import javax.resource.ResourceException;
import javax.resource.spi.ConnectionManager;

import org.apache.log4j.Logger;
import org.fsconnector.spi.FSManagedConnectionFactory;

public class FSConnectionFactoryImpl implements FSConnectionFactory {

	private static final long serialVersionUID = 7090459890681028192L;
	private static final Logger logger = Logger.getLogger(FSConnectionFactoryImpl.class);

	private final ConnectionManager manager;
	private final FSManagedConnectionFactory factory;
	private Reference reference;

	public FSConnectionFactoryImpl(ConnectionManager manager,
			FSManagedConnectionFactory factory) {
		this.manager = manager;
		this.factory = factory;
	}

	public FSConnection getConnection() throws ResourceException {
		logger.debug("getConnection()");
		return (FSConnection) manager.allocateConnection(factory, null);
	}

//	public FSConnection getConnection(FSConnectionSpec spec)
//			throws ResourceException {
//		logger.debug("getConnection(" + spec + ")");
//		FSConnectionRequestInfo info;
//		if (spec == null || spec.getRootDir() == null) {
//			info = null;
//		} else {
//			String root = spec.getRootDir().trim();
//			if (root.equals("")) {
//				info = null;
//			} else {
//				info = new FSConnectionRequestInfo(new File(root));
//			}
//		}
//
//		return (FSConnection) manager.allocateConnection(factory, info);
//	}

	public void setReference(Reference reference) {
		this.reference = reference;
	}

	public Reference getReference() throws NamingException {
		return reference;
	}

}
